<template>
	<view class="content">
		<post-list-cell class="forum_post_cell_content" v-for="(item,index) in items" :key="index" :item="item">
		</post-list-cell>
	</view>
</template>


<script>
	import http from "../../utils/http.js"
	import util from "../../utils/util.js"
	export default {
		data() {
			return {
				keyword: "",
				page:1,
				items:[]
			}
		},
		onLoad(option){
			uni.setNavigationBarTitle({
				title:option.keyword
			})
			this.keyword = option.keyword?option.keyword:"";
			this.loadData();
		},
		onPullDownRefresh(){
			this.loadData();
		},
		onReachBottom(){
			this.loadMoreData();
		},
		methods: {
			loadData(){
				var that = this;
				http.request("forum/search",{pageSize : 20,page: 1,keyword:this.keyword},{
					success:function(data){
						uni.stopPullDownRefresh();
						that.items = data.list.map(function(item){
							item.showTime = util.dateStringFromTimestamp(item.last_reply_date);
							return item;
						})
						that.page = 2;
					},
					fail: function(msg) {
						uni.stopPullDownRefresh();
						uni.showToast({
							title:msg,
							icon:"none"
						})
					}
				})
			},
			loadMoreData(){
				var that = this;
				http.request("forum/search",{pageSize : 20,page: this.page,keyword:this.keyword},{
					success:function(data){
						var items = that.items.concat( data.list.map(function(item){
							item.showTime = util.dateStringFromTimestamp(item.last_reply_date);
							return item;
						}))
						that.items = items;
						that.page ++;
					},
					fail: function(msg) {
						uni.showToast({
							title:msg,
							icon:"none"
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		width: 100%;
		flex-direction: column;
	}
</style>
